<?php 
	require_once($_SERVER['DOCUMENT_ROOT']."/model/data_service.php");
    require_once($_SERVER['DOCUMENT_ROOT']."/model/helper.php");
    if (isset($_GET)  &&  array_key_exists("location",$_GET) &&  array_key_exists("page",$_GET) && array_key_exists("trigger_category",$_GET))
	{
        $location = explode(",",$_GET["location"],3);
        $continent=$country=$city=NULL;
        count($location) ==2?list($continent,$country) = array_map(function($i){return !empty($i)?$i:NULL;},$location):FALSE;
        count($location) ==3?list($continent,$country,$city) = array_map(function($i){return !empty($i)?$i:NULL;},$location):FALSE;
        $result = [];
        $page = $_GET["page"];
        switch($_GET["trigger_category"])
        {
            case Categories::ACCOMMODATION:
                $service_fil = array_key_exists("service_fil",$_GET)?$_GET["service_fil"]:-1;
                $rating_fil = array_key_exists("rating_fil",$_GET)?$_GET["rating_fil"]:NULL;
                $result = all_accommodation($continent,$country,$city,$page,["hotel_service"=>$service_fil,"hotel_rating"=>$rating_fil]);
                break;
            case Categories::TRANSPORT:
                $result = all_transport($continent,$country,$city,$page,[]);
                break;
            case Categories::SHOPPING:
                $result = all_shopping($continent,$country,$city,$page,[]);
                break;
            case Categories::ATTRACTION:
                $result = all_attraction($continent,$country,$city,$page,[]);
                break;
            case Categories::FOOD:
                $result = all_food($continent,$country,$city,$page,[]);
                break;
        }
        
        echo json_encode($result);
        //drupal_json_output($result);
	}
?>